﻿@using DTD.Repositories
@model List<Category>
@{string dialogId = "editTaskDialog";}

<style>
    #@dialogId input[type=text] {width: 100%}
    #@dialogId textarea {width: 100%; height: 70px;}
</style>
<script type="text/javascript">
    $(function () {
        $("#@dialogId").dialog({ height: 260, modal: true, autoOpen: false });
        var availableTags = [
            @foreach(var c in Model)
            {
                MvcHtmlString cat = MvcHtmlString.Create("\"" + c.Title + "\",");
                @cat
            }
            "Дела"
		];
        // Autocomplete
        $("#TaskCategories").autocomplete({source: availableTags});
    });

    function openEditDialog(name, description, id, category) {
        $('#TaskName').attr("value", name);
        $('#TaskDescription').attr("value", description);
        $("#TaskId").attr("value", id);
        $("#TaskCategories").attr("value", category);
        $("#@dialogId").dialog('open');
    }

    function closeEditDialog(result) {
        $("#@dialogId").dialog('close');
        location.reload(true);
    }

    function failedEdit(result, Data) {
        alert(Data);
    }
    </script>
    <div id="@dialogId" title="Редактировать задачу" style="display: none">
        @using(Ajax.BeginForm("Edit", "Tasks", new AjaxOptions{OnSuccess = "closeEditDialog", OnFailure = "failedEdit", HttpMethod = "Post"}))
        {
            <input type="hidden" name="Id" id="TaskId"/>
            <div>Название:</div>
            <div><input  id="TaskName" type="text" name="Title"/></div>
            <div>Описание:</div>
            <div><textarea id="TaskDescription" name="Description"></textarea></div>
            <div>Категория:</div>
            <div>
                <input id="TaskCategories" type="text" name="category"/>
            </div>
            <div><input type="submit" value="Сохранить"/></div>
        }
    </div>

